<%@ page contentType="text/html; charset=utf-8" %>

<%@ include file="/WEB-INF/jsp/includeTaglib.jsp" %>
<div id="ajaxpagetoolbar">
		<input type="hidden" id="insertRuleTemplateKey" name="insertRuleTemplateKey">
    <table width="100%" border="0" cellpadding="0" cellspacing="1">
       <tr class="rowHead">
         <td height="20" width="20" align="center"><input type="checkbox" id="checkAll" onclick="javascript:checkAllOrNot();"></td>
         <td height="20" width="150" nowrap align="center" class="globalTextBold">通信规则模板编号</td>
         <td height="20" width="180" nowrap align="center" class="globalTextBold">模板描述</td>							
       </tr>
       <c:if test="${empty ruleTemplates}">
        <tr class="rowEven">
         <td colspan="7" align="center" class="globalText">无数据</td>
        </tr>
			</c:if>
       <c:forEach var="ruleTemplate" items="${ruleTemplates}" varStatus="status">
        <c:choose>
         <c:when test="${status.index % 2 == 0}">
         <tr class="rowEven">
         </c:when>
         <c:otherwise>
         <tr class="rowOdd">
         </c:otherwise>
        </c:choose>
          <td height="20" width="20" align="center"><input type="checkbox" name="cbIds" value="${ruleTemplate.customId}" onclick="javascript:checkPerBox();"></td>
          <td height="20" class="globalText">${ruleTemplate.customId}</td>
          <td height="20" class="globalText">${ruleTemplate.description}</td>
        </tr>
       </c:forEach>
       <tr>
         <td align="left" colspan="2">
           <table border="0" cellpadding="0" cellspacing="2">
             <tr>
               <td><input id="insertRuleTemplateBtn" type="button" class="btnStyle" value="  插入"></td>
             </tr>
           </table>
         </td>
       </tr>
    </table>

<%@ include file="/WEB-INF/jsp/includePagedDisplayAjax.jsp" %>
</div>


<script type="text/javascript">

	function checkInsert() {
		if(document.getElementsByName("cbIds") == null){
			return false;
		}

		if(!checkAtLeastOne()){
			alert("请至少选择一条记录");
			return false;
		}

		if(!checkOnlyOne()){
			alert("请只选择一条记录");
			return false;
		}

		if (document.getElementsByName("cbIds").length == 1){
			document.getElementById("insertRuleTemplateKey").value = document.getElementsByName("cbIds")[0].value;
		}else{
			for(var i=0;i<document.getElementsByName("cbIds").length;i++){
				if(document.getElementsByName("cbIds")[i].checked){
					document.getElementById("insertRuleTemplateKey").value = document.getElementsByName("cbIds")[i].value;
					break;
				}
			}
		}
		return true;
	}

	$(document).ready(function() {
		  $("#insertRuleTemplateBtn").click(function(){
			  if(checkInsert()) {
				  var insertRuleTemplateKey = $("#insertRuleTemplateKey").val();
					$("#msgRuleTemplateIdTxt").val(insertRuleTemplateKey);
				}
		  });
	});

</script>